package com.ruoyi.DegreePoints.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.user.domain.Users;
import com.ruoyi.user.mapper.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.DegreePoints.mapper.DegreePointsMapper;
import com.ruoyi.DegreePoints.domain.DegreePoints;
import com.ruoyi.DegreePoints.service.IDegreePointsService;

/**
 * 学位点Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@Service
public class DegreePointsServiceImpl extends ServiceImpl<DegreePointsMapper,DegreePoints> implements IDegreePointsService
{
    @Autowired
    private DegreePointsMapper degreePointsMapper;

    @Autowired
    private UsersMapper usersMapper;

    /**
     * 查询学位点
     * 
     * @param pointId 学位点主键
     * @return 学位点
     */
    @Override
    public DegreePoints selectDegreePointsByPointId(Long pointId)
    {
        DegreePoints degreePoints = degreePointsMapper.selectDegreePointsByPointId(pointId);
        Users users = usersMapper.selectExpertName(degreePoints.getPointId());
        if(users != null){
            degreePoints.setExpertName(users.getRealName());
            degreePoints.setExpertId(users.getUserId());
        }else {
            degreePoints.setExpertName("未分配专家");
            degreePoints.setExpertId(0L);
        }
        return degreePoints;
    }

    /**
     * 查询学位点列表
     * 
     * @param degreePoints 学位点
     * @return 学位点
     */
    @Override
    public List<DegreePoints> selectDegreePointsList(DegreePoints degreePoints)
    {
        List<DegreePoints> degreePoints1 = degreePointsMapper.selectDegreePointsList(degreePoints);
        degreePoints1.forEach(d -> {
            Users users = usersMapper.selectExpertName(d.getPointId());
            if(users != null){
                d.setExpertName(users.getRealName());
                d.setExpertId(users.getUserId());
            }else {
                d.setExpertName("未分配专家");
                d.setExpertId(0L);
            }

        });
        return degreePoints1;
    }

    /**
     * 新增学位点
     * 
     * @param degreePoints 学位点
     * @return 结果
     */
    @Override
    public int insertDegreePoints(DegreePoints degreePoints)
    {
        return degreePointsMapper.insertDegreePoints(degreePoints);
    }

    /**
     * 修改学位点
     * 
     * @param degreePoints 学位点
     * @return 结果
     */
    @Override
    public int updateDegreePoints(DegreePoints degreePoints)
    {
        return degreePointsMapper.updateDegreePoints(degreePoints);
    }

    /**
     * 批量删除学位点
     * 
     * @param pointIds 需要删除的学位点主键
     * @return 结果
     */
    @Override
    public int deleteDegreePointsByPointIds(Long[] pointIds)
    {
        return degreePointsMapper.deleteDegreePointsByPointIds(pointIds);
    }

    /**
     * 删除学位点信息
     * 
     * @param pointId 学位点主键
     * @return 结果
     */
    @Override
    public int deleteDegreePointsByPointId(Long pointId)
    {
        return degreePointsMapper.deleteDegreePointsByPointId(pointId);
    }
}
